# !/usr/bin/env python
# -*- coding:utf-8 -*-
# project name: CP_Automation
# author: "SongFang" 
# creation time: 2018/6/28 11:41
# Email: geg726@163.com

import unittest
from Operation.element import Element
from selenium.webdriver.common.keys import Keys
import time


el = Element()

def login(user, passwd):
    #用户名删除
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').click()
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(Keys.CONTROL + 'a')
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(Keys.BACKSPACE)

    #密码删除
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').click()
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(Keys.CONTROL + 'a')
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(Keys.BACKSPACE)

    #用户名密码封装
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[1]/input').send_keys(user)
    el.xpath('//*[@id="app"]/div/div/content/div[2]/div[2]/input').send_keys(passwd)

class Test(unittest.TestCase):
    """火狐浏览器H5测试"""

    @classmethod
    def setUpClass(cls):
        cls.driver = el.Driver()
        el.openurl("http://192.168.1.190/mayi-h5/index.html#/home/my")
        el.xpath("//span[text()='点击登录']").send_keys(Keys.F12)
        el.xpath("//span[text()='点击登录']").send_keys(Keys.CONTROL, Keys.SHIFT, 'm')
        el.xpath("//span[text()='点击登录']").click()



    def test02(self):
        """H5不输入用户名登录"""
        login('', '123456')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"),'登录失败')

    def test03(self):
        """H5不输入密码登录"""
        login('pc001', '')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test04(self):
        """H5账户名与密码不匹配登录"""
        login('pc001','123111')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test05(self):
        """H5账户名不存在登录"""
        login('sadsadssd','123456')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')

    def test6(self):
        """H5正常用户名密码登录"""
        login('pc001','123456')
        el.xpath('//*[@id="app"]/div/div/content/div[2]/div[3]').click()
        time.sleep(2)
        self.assertTrue(el.trywait_assert_xpath("//span[text()='投注记录']"), '登录失败')




    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
